#!/bin/sh
main()
{
user_strs=`. $DOCUMENT_ROOT/apps/sysusers/sysusers.sbin get_sysusers`

. $DOCUMENT_ROOT/apps/home/header.tpl.sh
header_html
cat <<'EOF'
<script>
$(function(){
  $('#post_chpass').on('submit', function(e){
    e.preventDefault();
    var data = "app=password&"+$(this).serialize();
    var url = 'index.cgi';
    Ha.common.ajax(url, 'json', data, 'post', 'ajax-fluid');
  });
});
</script>
EOF
cat <<EOF
		<div class="pure-g">
			<div class="l-box-lrg pure-u-1">
				<h3>管理员用户名和密码修改</h3>
				<form class="pure-form pure-form-stacked" id="post_chpass">
<table class="pure-table pure-table-bordered">
<thead><tr><th>uid</th><th>_LANG_Username</th><th>_LANG_Password</th><th>_LANG_GID</th><th>_LANG_Desc</th><th>_LANG_Home</th><th>shell</th><th>_LANG_Option</th></tr></thead>
EOF
. /usr/share/libubox/jshn.sh
json_init
json_load "$user_strs"
json_select "sysusers"
json_get_keys keys
for key in $keys
do
json_select ${key}
json_get_vars uid username passwd gid desc home shell
cat <<EOF
<tr>
	<td>
		${uid}
	</td>
	<td>
		${username}
	</td>
	<td style=\"width: 20%\">
		${passwd}
	</td>
	<td>
		${gid}
	</td>
	<td>
		${desc}
	</td>
	<td>
		${home}
	</td>
	<td>
		${shell}
	</td>
	<td>
		<a class="pure-button" href="index.cgi?app=sysusers&action=edituser&username=${username}">_LANG_Edit</a>
EOF
if [ "$username" != "root" ] ; then
cat <<EOF
		<a class="button-error pure-button" href="index.cgi?app=sysusers&action=deluser&username=${username}">_LANG_Del</a>
EOF
fi
cat <<EOF
	</td>
</tr>
EOF
json_select ..
done
# echo "$user_pass_str" | awk -F ":" '{if ($1 == "root") print "<tr><td>"$3"</td><td>"$1"</td><td style=\"width: 20%\">"$9"</td><td>:"$4":</td><td>"$5"</td><td>"$6"</td><td>"$7"</td><td><a class=\"pure-button\" href=\"index.cgi?app=sysusers&action=edituser&username="$1"\">'_LANG_Edit'</a></td></tr>";else print "<tr><td>"$3"</td><td>"$1"</td><td style=\"width: 20%\">"$9"</td><td>:"$4":</td><td>"$5"</td><td>"$6"</td><td>"$7"</td><td><a class=\"pure-button\" href=\"index.cgi?app=sysusers&action=edituser&username="$1"\">'_LANG_Edit'</a><a class=\"button-error pure-button\" href=\"index.cgi?app=sysusers&action=deluser&username="$1"\">'_LANG_Del'</a></td></tr>"}'
cat <<EOF
</table>
				</form>
				<br/>
				<br/>
			</div>
		</div>
EOF
footer_html
}

post_chpass()
{
if
[ "$FORM_password" = "$FORM_password_cf" ]
then
passwd root <<EOF >/dev/null 2>&1
$FORM_password
$FORM_password_cf
EOF
echo "密码修改成功!!" | main.sbin output_json 0
else
echo "两次输入密码不同!" | main.sbin output_json 1
EOF
fi
}

lang=`main.sbin get_client_lang`
eval `cat $DOCUMENT_ROOT/apps/$FORM_app/i18n/$lang/i18n.conf`
if
[ $is_main_page = 1 ]
then
main
elif [ -n "$FORM_action" ]
then
$FORM_action
fi
